import sqlite3

# 连接旧数据库和新数据库
old_conn = sqlite3.connect('data.old.db')
new_conn = sqlite3.connect('data.db')
old_cursor = old_conn.cursor()
new_cursor = new_conn.cursor()


# clients 表数据迁移
# 从旧数据库中获取数据
old_cursor.execute("SELECT client_id, client_name, client_ip, client_type, client_info, client_secret FROM clients")
old_data = old_cursor.fetchall()
# 将数据插入新数据库
for row in old_data:
    new_cursor.execute("INSERT INTO clients (client_id, client_name, client_ip, client_type, client_info, client_secret) VALUES (?, ?, ?, ?, ?, ?)", (*row,))


# tasks 表数据迁移
# 从旧数据库中获取数据
old_cursor.execute("SELECT client_id, task_name, client_ip, client_port, task_type, task_enable FROM tasks")
old_data = old_cursor.fetchall()
# 将数据插入新数据库
for row in old_data:
    new_cursor.execute("INSERT INTO tasks (client_id, task_name, client_ip, client_port, task_type, task_enable) VALUES (?, ?, ?, ?, ?, ?)", (*row,))


# 提交更改并关闭连接
new_conn.commit()
old_conn.close()
new_conn.close()

print("数据迁移完成！")
